<?php 
	include '../init.php';
	include ADMIN_PATH.'/header.php';
	$id=$_GET['id'];
	$model=new Model('order_info');
	//每页多少条
	$num=2;
	//查询总条数
	 $sql2="select count(*) 
		 	from 
			 	`goods` g,
			 	`goods_img` gi,
			 	`order_info` oi 
	 		where 
			    g.id=gi.goods_id
			   and 
			    oi.goods_id=g.id
			   and
			   	gi.is_cover=1
			   and
			   	oi.order_id=$id
			 ";
	
	//总条数
	$total=$model->find($sql2)[0]['count(*)'];
	//var_dump($total);
	//总页数
	$pages=ceil($total/$num);
	//var_dump($pages);
	//获取当前页
	$p=$_GET['p']?$_GET['p']:1;
	//尾页处理
	$p=min($p,$pages);
	//首页处理
	$p=max($p,1);
	//上一页
	$prev=$p-1;
	//下一页
	$next=$p+1;

	//每页开始
	$start=($p-1)*$num;
	//每页结束(偏移量)
	$offset=$num;
	$sql="select 
			g.id 		  gid,
			g.name 		  gname,
			g.price 	  gp,
			g.description gd,
			g.addtime     gtime,
			gi.name 	  giname,
			oi.num 		  oinum 
		   from 
		    goods 		  g,
		    goods_img     gi,
		    order_info	  oi
		   where 
		    g.id=gi.goods_id
		   and 
		    oi.goods_id=g.id
		   and
		   	gi.is_cover=1
		   and
		   	oi.order_id=$id
		   	limit $start,$offset
		  ";
	$goods_list=$model->find($sql);

	$str="
		<a href='".ADMIN_URL."/order/detail.php?id=".$id."' style=color:#ED145B;>首页</a>
		<a href='".ADMIN_URL."/order/detail.php?p=$prev&id=".$id."' style=color:#ED145B;>上一页</a>
		<a href='".ADMIN_URL."/order/detail.php?p=$p&id=".$id."' style=color:#ED145B;>$p</a>
		<a href='".ADMIN_URL."/order/detail.php?p=$next&id=".$id."' style=color:#ED145B;>下一页</a>
		<a href='".ADMIN_URL."/order/detail.php?p=$pages&id=".$id."' style=color:#ED145B;>尾页</a>
		";
?>
<div class="m_right">
	<div class="m_main">
		<h2 style="display:block;width:100px;height:50px;margin-left:40px;margin-top:20px;">我的订单</h2>
				<table border="1" cellpadding="5" cellspacing="0" width="92%" style="margin:20px auto;text-align:center;margin-top:50px;">
					<tr height="60px;">
						<th>商品编号</th>
						<th>商品名称</th>
						<th>商品图片</th>
						<th>商品描述</th>
						<th>单价</th>
						<th>数量</th>
						<th>小计</th>
						<th>添加时间</th>
					</tr>
					<?php foreach ($goods_list as $key => $value): ?>
						<tr height="60">
							<td><?php echo $value['gid'];?></td>
							<td><?php echo $value['gname'];?></td>
							<td><img src="<?php echo URL.'/public/uploads/'.substr($value['giname'],0,4).'/'.substr($value['giname'], 4,2).'/'.substr($value['giname'],6,2).'/50_'.$value['giname'];?>" alt="美工回家生娃了"/></td>
							<td><?php echo $value['gd'];?></td>
							<td><font style="color:red;">¥:<?php echo $value['gp'];?></font></td>
							<td><?php echo $value['oinum'];?></td>
							<td><font style="color:red;">¥:<?php echo $value['gp']*$value['oinum'];?></font></td>
							<td><?php echo date('Y年m月d日',$value['gtime']);?></td>
						</tr>
					<?php endforeach ?>
					<tr>
						<th colspan="8" height="50px">
							<?php echo $str;?>
						</th>
					</tr>
				</table>
	</div>
</div>
<?php 
	include ADMIN_PATH.'/footer.html';
?>